import Vue from 'vue'
import VueRouter from 'vue-router'
import {getCookie} from "@/utils/Cookie";


Vue.use(VueRouter)

let routesMb = [
    {
        path: '/purchasing',
        name: 'purchasing',
        meta:{keep:false,menu:4,isTab:false},
        component: () => import(/* webpackChunkName: "about" */ '../views/purchasing/index.vue')
    },
    {
        path: '/revenue',
        name: 'revenue',
        meta:{keep:false,menu:4,isTab:false},
        component: () => import(/* webpackChunkName: "about" */ '../views/revenue/index.vue')
    },
    {
        path: '/service',
        name: 'service',
        meta:{keep:false,menu:4,isTab:false},
        component: () => import(/* webpackChunkName: "about" */ '../views/service/index.vue')
    },
    {
        path: '/recharge',
        name: 'recharge',
        meta:{keep:false,menu:4,isTab:false},
        component: () => import(/* webpackChunkName: "about" */ '../views/recharge/index.vue')
    },
    {path: '/withdrawal', name: 'withdrawal', meta:{keep:false,menu:1,isTab:false}, component: () => import( '../views/withdrawal/index.vue')},
    {path: '/withdrawalRecord', name: 'withdrawalRecord', meta:{keep:false,menu:1,isTab:false}, component: () => import( '../views/withdrawal/record.vue')},
    {path: '/wallet', name: 'wallet', meta:{keep:false,menu:1,isTab:false}, component: () => import( '../views/wallet/index.vue')},
    {path: '/', name: 'home', meta:{keep:false,menu:1,isTab:true}, component: () => import( '../views/home/index.vue')},
    {path: '/invest', name: 'invest', meta:{keep:false,menu:2,isTab:true}, component: () => import( '../views/invest/index.vue')},
    {path: '/buy', name: 'buy', meta:{keep:false,menu:5,isTab:true}, component: () => import( '../views/buy/index.vue')},
    {path: '/record', name: 'record', meta:{keep:false,menu:3,isTab:true}, component: () => import( '../views/record/index.vue')},
    {path: '/my', name: 'my', meta:{keep:false,menu:4,isTab:true}, component: () => import( '../views/my/index.vue')},
    {path: '/invite', name: 'invite', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/invite/index.vue')},
    {path: '/download', name: 'download', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/download/index.vue')},
    {path: '/team', name: 'team', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/team/index.vue')},
    {path: '/password', name: 'password', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/loginPassword/index.vue')},
    {path: '/transaction', name: 'transaction', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/transactionPassword/index.vue')},
    {path: '/login', name: 'login', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/login/index.vue')},
    {path: '/reg', name: 'reg', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/reg/index.vue')},
    {path: '/agree', name: 'agree', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/agreement/index.vue')},
    {path: '/introduct', name: 'introduct', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/introduct/index.vue')},
    {path: '/helpInfo', name: 'helpInfo', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/help/helpInfo.vue')},
    {path: '/help', name: 'help', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/help/index.vue')},
    {path: '/pay', name: 'pay', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/recharge/pay.vue')},
    {path: '/join', name: 'join', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/join/index.vue')},
    {path: '/payment', name: 'payment', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/payment/index.vue')},
    {path: '/mission', name: 'mission', meta:{keep:false,menu:4,isTab:false}, component: () => import( '../views/mission/index.vue')},
]

let routesPc=[
    {path: '/', name: 'home', component: () => import( '../page/index.vue')}

]

var routes=[]
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    routes = routesMb
} else {
    routes = routesPc
}

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
    scrollBehavior: () => ({ y: 0 }),//每次都跳转到顶部
})

router.beforeEach((to, from, next) => {
    let token = getCookie('like-admin')
    if (token){
        next()
    }else{
        if (/login|reg|agree/.test(to.path)){
            next()
        }else{
            router.push('/login').catch(err=>{})
        }
    }
})


export default router
